#!/usr/bin/env ruby

ENV['STARMAN_ROOT'] = File.absolute_path(File.dirname __FILE__)

require "#{ENV['STARMAN_ROOT']}/framework"

begin
  command_name = ARGV.shift.to_sym
rescue
  CLI.error 'No command is provided!'
end

aliases = {
  i: :install,
  rm: :uninstall,
  c: :config,
  e: :edit,
  u: :update,
  ls: :list
}

commands = {
  setup: SetupCommand,
  list: ListCommand,
  install: InstallCommand,
  uninstall: UninstallCommand,
  load: LoadCommand,
  debug_load: LoadCommand,
  config: ConfigCommand,
  edit: EditCommand,
  link: LinkCommand,
  unlink: UnlinkCommand,
  pack: PackCommand,
  update: UpdateCommand,
  fix: FixCommand
}

OS.init
Runtime.init

CLI.error "Unknown command #{CLI.red command_name}!" unless commands.has_key? command_name or aliases.has_key? command_name
command = (commands[command_name] || commands[aliases[command_name]]).new

command.run
